class SC_DLLPUBLIC ExternalDataMapper
{
- //ScDocument& mrDoc;
+ ScDocument& mrDoc;
std::vector<ExternalDataSource> maDataSources;
public:
SC_DLLPUBLIC ScDBData* GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
void RefreshDirtyTableColumnNames();
SC_DLLPUBLIC sc::ExternalDataMapper& GetExternalDataMapper();
+ /** True when the document holds at least one external data mapping. Checks
+ without creating the mapper, so it stays cheap for documents that have
+ none. */
+ SC_DLLPUBLIC bool HasDataProviderMappings() const;
SC_DLLPUBLIC const ScRangeData* GetRangeAtBlock( const ScRange& rBlock, OUString& rName,
bool* pSheetLocal = nullptr ) const;
return *mpDataMapper;
}
+bool ScDocument::HasDataProviderMappings() const
+{
+ return mpDataMapper && !mpDataMapper->getDataSources().empty();
+}
+
void ScDocument::StoreTabToCache(SCTAB nTab, SvStream& rStrm) const
{
const ScTable* pTab = FetchTable(nTab);
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <comphelper/embeddedobjectcontainer.hxx>
#include <comphelper/fileformat.h>
#include <comphelper/string.hxx>
#include <osl/thread.h>
#include <ddelink.hxx>
#include <brdcst.hxx>
+#include <docsh.hxx>
#include <document.hxx>
#include <scmatrix.hxx>
#include <patattr.hxx>
sfx2::SvBaseLink::UpdateResult ScDdeLink::DataChanged(
const OUString& rMimeType, const css::uno::Any & rValue )
{
+ if (rDoc.GetDocumentShell()
+ && !rDoc.GetDocumentShell()->GetEmbeddedObjectContainer().getUserAllowsLinkUpdate())
+ return SUCCESS;
+
// we only master strings...
if ( SotClipboardFormatId::STRING != SotExchange::GetFormatIdFromMimeType( rMimeType ))
return SUCCESS;
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
+#include <comphelper/embeddedobjectcontainer.hxx>
#include <comphelper/processfactory.hxx>
#include <sfx2/linkmgr.hxx>
#include <sfx2/bindings.hxx>
#include <utility>
#include <webservicelink.hxx>
#include <brdcst.hxx>
+#include <docsh.hxx>
#include <document.hxx>
#include <sc.hrc>
sfx2::SvBaseLink::UpdateResult ScWebServiceLink::DataChanged(const OUString&, const css::uno::Any&)
{
+ if (pDoc && pDoc->GetDocumentShell()
+ && !pDoc->GetDocumentShell()->GetEmbeddedObjectContainer().getUserAllowsLinkUpdate())
+ return SUCCESS;
+
aResult.clear();
bHasResult = false;
}
}
-ScXMLMappingContext::~ScXMLMappingContext()
-{
- ScDocument* pDoc = GetScImport().GetDocument();
- auto& rDataMapper = pDoc->GetExternalDataMapper();
- auto& rDataSources = rDataMapper.getDataSources();
- if(!rDataSources.empty())
- rDataSources[0].refresh(pDoc, true);
-}
-
uno::Reference<xml::sax::XFastContextHandler>
SAL_CALL ScXMLMappingContext::createFastChildContext(
sal_Int32 nElement, const uno::Reference<xml::sax::XFastAttributeList>& /*xAttrList*/)
ScXMLMappingContext( ScXMLImport& rImport,
const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList );
- virtual ~ScXMLMappingContext() override;
-
virtual css::uno::Reference<css::xml::sax::XFastContextHandler> SAL_CALL createFastChildContext(
sal_Int32 nElement,
const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList) override;
#include <datamapper.hxx>
#include <dbdata.hxx>
#include <docsh.hxx>
+#include <document.hxx>
+#include <comphelper/embeddedobjectcontainer.hxx>
+#include <sfx2/lnkbase.hxx>
+#include <sfx2/linkmgr.hxx>
#include <utility>
using namespace com::sun::star;
return maDataTransformations;
}
-ExternalDataMapper::ExternalDataMapper(ScDocument& /*rDoc*/)
- //mrDoc(rDoc)
+namespace {
+
+// A data mapping fetches external data (CSV, HTML, XML) into a sheet. It is
+// registered in the LinkManager so it passes through the same link update
+// control as sheet links, area links, and external references. The link holds
+// the index of its data source in the mapper. That index is stable because
+// data sources are only ever appended, never removed.
+class ScDataProviderLink final : public sfx2::SvBaseLink
+{
+ ScDocShell& mrDocShell;
+ size_t mnSourceIndex;
+
+public:
+ ScDataProviderLink(ScDocShell& rDocShell, size_t nSourceIndex)
+ : sfx2::SvBaseLink(SfxLinkUpdateMode::ONCALL, SotClipboardFormatId::SIMPLE_FILE)
+ , mrDocShell(rDocShell)
+ , mnSourceIndex(nSourceIndex)
+ {
+ }
+
+ virtual sfx2::SvBaseLink::UpdateResult DataChanged(const OUString&,
+ const css::uno::Any&) override
+ {
+ if (!mrDocShell.GetEmbeddedObjectContainer().getUserAllowsLinkUpdate())
+ return SUCCESS;
+
+ ScDocument& rDoc = mrDocShell.GetDocument();
+ std::vector<sc::ExternalDataSource>& rSources
+ = rDoc.GetExternalDataMapper().getDataSources();
+ if (mnSourceIndex < rSources.size())
+ rSources[mnSourceIndex].refresh(&rDoc, true);
+
+ return SUCCESS;
+ }
+};
+
+}
+
+ExternalDataMapper::ExternalDataMapper(ScDocument& rDoc)
+ : mrDoc(rDoc)
{
}
void ExternalDataMapper::insertDataSource(const sc::ExternalDataSource& rSource)
{
maDataSources.push_back(rSource);
+
+ ScDocShell* pDocShell = mrDoc.GetDocumentShell();
+ if (!pDocShell)
+ return;
+
+ sfx2::LinkManager* pLinkManager = mrDoc.GetLinkManager();
+ if (!pLinkManager)
+ return;
+
+ ScDataProviderLink* pLink = new ScDataProviderLink(*pDocShell, maDataSources.size() - 1);
+ const OUString& rProvider = rSource.getProvider();
+ pLinkManager->InsertFileLink(*pLink, sfx2::SvBaseLinkObjectType::ClientFile,
+ rSource.getURL(), &rProvider, nullptr);
}
const std::vector<sc::ExternalDataSource>& ExternalDataMapper::getDataSources() const
rHelpBtn.set_label(GetStandardText(StandardButtonType::Help).replaceFirst("~", ""));
rHelpBtn.connect_clicked(LINK(nullptr, LinkHelp, DispatchHelpLinksHdl));
weld::Button& rBtn = pInfoBar->addButton();
+ rBtn.set_buildable_name(u"allowupdating"_ustr);
rBtn.set_label(ScResId(STR_ENABLE_CONTENT));
rBtn.set_tooltip_text(ScResId(STR_ENABLE_CONTENT_TOOLTIP));
rBtn.connect_clicked(LINK(this, ScDocShell, ReloadAllLinksHdl));
#include <tools/urlobj.hxx>
#include <unotools/transliterationwrapper.hxx>
#include <comphelper/configuration.hxx>
+#include <comphelper/embeddedobjectcontainer.hxx>
#include <comphelper/processfactory.hxx>
#include <tablink.hxx>
if (!bLink)
{
const sc::DocumentLinkManager& rMgr = rDoc.GetDocLinkManager();
- if (rDoc.HasLinkFormulaNeedingCheck() || rDoc.HasAreaLinks() || rMgr.hasExternalLinks())
+ if (rDoc.HasLinkFormulaNeedingCheck() || rDoc.HasAreaLinks()
+ || rDoc.HasDataProviderMappings() || rMgr.hasExternalLinks())
bLink = true;
}
if (bLink)